/**
  ******************************************************************************
  * @file    bsp_led.c
  * @author  zwx
  * @version V1.0.0
  * @date    2019-09-21
  * @brief
  ******************************************************************************
  */

#include "bsp_led.h"


/* Exported variables --------------------------------------------------------*/
/* Exported functions --------------------------------------------------------*/
/* Private typedef -----------------------------------------------------------*/
/* Private struct  -----------------------------------------------------------*/
/* Private define ------------------------------------------------------------*/
/* Private macro -------------------------------------------------------------*/
/* Private variables ---------------------------------------------------------*/
/* Private functions ---------------------------------------------------------*/


/**
  * @brief
  * @param  None
  * @retval None
  */
void bsp_ledInit(void)
{
    GPIO_InitTypeDef GPIO_InitStructure;

    LED_RCC_INIT();

    GPIO_InitStructure.GPIO_Pin = LED_POWER_PIN;
    GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
    GPIO_InitStructure.GPIO_Speed = GPIO_Speed_10MHz;
    GPIO_Init(LED_POWER_PORT, &GPIO_InitStructure);

    GPIO_InitStructure.GPIO_Pin = LED_WORK_PIN;
    GPIO_Init(LED_WORK_PORT, &GPIO_InitStructure);

    GPIO_InitStructure.GPIO_Pin = LED_FAULT_PIN;
    GPIO_Init(LED_FAULT_PORT, &GPIO_InitStructure);

    GPIO_SetBits(LED_POWER_PORT, LED_POWER_PIN);
    GPIO_SetBits(LED_WORK_PORT, LED_WORK_PIN);
    GPIO_SetBits(LED_FAULT_PORT, LED_FAULT_PIN);
}


void led_off(uint8_t n)
{
    switch(n)
    {
        case LED_POWER:
            GPIO_SetBits(LED_POWER_PORT, LED_POWER_PIN);
            break;
        case LED_WORK:
            GPIO_SetBits(LED_WORK_PORT, LED_WORK_PIN);
            break;
        case LED_FAULT:
            GPIO_SetBits(LED_FAULT_PORT, LED_FAULT_PIN);
            break;
        default:
            break;

    }
}

void led_on(uint8_t n)
{
    switch(n)
    {
        case LED_POWER:
            GPIO_ResetBits(LED_POWER_PORT, LED_POWER_PIN);
            break;
        case LED_WORK:
            GPIO_ResetBits(LED_WORK_PORT, LED_WORK_PIN);
            break;
        case LED_FAULT:
            GPIO_ResetBits(LED_FAULT_PORT, LED_FAULT_PIN);
            break;
        default:
            break;

    }
}

void led_toggle(uint8_t n)
{
    switch(n)
    {
        case LED_POWER:
            if(0 == GPIO_ReadInputDataBit(LED_POWER_PORT, LED_POWER_PIN))
            {
                GPIO_SetBits(LED_POWER_PORT, LED_POWER_PIN);
            }
            else
            {
                GPIO_ResetBits(LED_POWER_PORT, LED_POWER_PIN);
            }
            break;
        case LED_WORK:
            if(0 == GPIO_ReadInputDataBit(LED_WORK_PORT, LED_WORK_PIN))
            {
                GPIO_SetBits(LED_WORK_PORT, LED_WORK_PIN);
            }
            else
            {
                GPIO_ResetBits(LED_WORK_PORT, LED_WORK_PIN);
            }
            break;
        case LED_FAULT:
            if(0 == GPIO_ReadInputDataBit(LED_FAULT_PORT, LED_FAULT_PIN))
            {
                GPIO_SetBits(LED_FAULT_PORT, LED_FAULT_PIN);
            }
            else
            {
                GPIO_ResetBits(LED_FAULT_PORT, LED_FAULT_PIN);
            }
            break;
        default:
            break;

    }
}

/*****************************  End   ******************************************/


